<template>
	<view>
		<view class="wrap">
				<cu-custom bgColor="bg-gradual-blue" :isBack="true">
					<block @click="goHome()" slot="backText">返回</block>
					<block slot="content">维保计划</block>
				</cu-custom>
				<unifab @dragClick="goHome" creatTop="70" creatLeft="85"imageBackgroundSize='100% 100%'  width='100rpx' height='100rpx' image="../../static/home.png" imageWidth="60upx"></unifab>
				<!-- 头部开始 -->
				<view class="goods-header-wrap">
					<view class="goods-header-item goods-header-item-action" :class="{'goods-header-item-active' : 1 == goodsNav}" @click="setNav(1)">
						<view v-if="count.overdue>0" class="cu-tag badge">{{count.overdue}}</view>已逾期
					</view>
					<view class="goods-header-item goods-header-item-action" :class="{'goods-header-item-active' : 2 == goodsNav}" @click="setNav(2)">
						<view v-if="count.undering>0" class="cu-tag badge">{{count.undering}}</view>维保中
					</view>
					<view class="goods-header-item goods-header-item-action" :class="{'goods-header-item-active' : 3 == goodsNav}" @click="setNav(3)">
						<view v-if="count.all>0" class="cu-tag badge">{{count.all}}</view>所有维保
					</view>
				</view>
			
				<view v-if="goodsNav!=3" v-for="(item, index) in dataList" class="goods-item-wrap">
					<view class="goods-content-wrap">
						<view @click="goJobDetail(item.Id,item.JobName)" class="goods-name">
							<view class="goods-name-title">{{item.JobName}}</view>
							<view class="select-icon"></view>
						</view>
						<view @click="goJobDetail(item.Id,item.JobName)" class="goods-stock-wrap">
							<view class="goods-stock">已维保 / 需维保</view>
							<view style="display: flex;">
								<view class="goods-stock-isok">{{item.QrcodeJobManageDetailList[0].signed}}</view>
								<view class="goods-stock-middle">/</view>
								<view class="goods-stock-notok">{{item.QrcodeJobManageDetailList[0].notSigned+item.QrcodeJobManageDetailList[0].signed}}</view>
							</view>
						</view>
						<view @click="goJobDetail(item.Id,item.JobName)" class="goods-stock-wrap">
							<view class="goods-stock">人员</view>
							<view class="goods-stock">{{item.qrcodeUserName}}</view>
						</view>
						<view class="goods-stock-wrap" style="border-bottom: 1px solid #F3F4F8;">
							<view class="goods-stock">周期</view>
							<view class="goods-stock-time">{{item.QrcodeJobManageDetailList[0].qrcodeJobTask}}</view>
						</view>
						<view v-if="item.IsTeam==1" class="goods-price1">团队模式</view>
						<view v-if="item.IsTeam!=1" class="goods-price2">个人模式</view>
						<view v-if="item.QrcodeJobManageDetailList[0].taskStatus==1" class="publish-goods-btn" @click="goOverdueWb(item.Id,item.QrcodeJobManageDetailList[0].qrcodeJobTask)">已逾期</view>
						<view v-if="item.QrcodeJobManageDetailList[0].taskStatus==2&&item.QrcodeJobManageDetailList[0].notSigned!=0" class="publish-goods-btn1" @click="goWB(item.Id,item.QrcodeJobManageDetailList[0].qrcodeJobTask)">去维保</view>
						<view v-if="item.QrcodeJobManageDetailList[0].taskStatus==2&&item.QrcodeJobManageDetailList[0].notSigned==0" class="publish-goods-btn2" @click="goWB(item.Id,item.QrcodeJobManageDetailList[0].qrcodeJobTask)">已完成</view>
					</view>
				</view>
				
				<view v-if="goodsNav==3" v-for="(item, index) in jobList" class="goods-item-wrap">
					<view class="goods-content-wrap">
						<view @click="goJobDetail(item.Id,item.JobName)" class="goods-name">
							<view class="goods-name-title">{{item.JobName}}</view>
							<view class="select-icon"></view>
						</view>
						<view @click="goJobDetail(item.Id,item.JobName)" class="goods-stock-wrap">
							<view class="goods-stock">循环周期</view>
							<view class="goods-stock">{{item.JobTaskName}}</view>
						</view>
						<view @click="goJobDetail(item.Id,item.JobName)" class="goods-stock-wrap">
							<view class="goods-stock">确认方式</view>
							<view class="goods-stock">{{item.MaintenanceConfirmName}}</view>
						</view>
						<view @click="goJobDetail(item.Id,item.JobName)" class="goods-stock-wrap">
							<view class="goods-stock">人员</view>
							<view class="goods-stock">{{item.qrcodeUserName}}</view>
						</view>
						<view class="goods-stock-wrap" style="border-bottom: 1px solid #F3F4F8;">
							<view class="goods-stock">计划期限</view>
							<view class="goods-stock-time">{{item.TimeSlot}}</view>
						</view>
						<view v-if="item.IsTeam==1" class="goods-price1">团队模式</view>
						<view v-if="item.IsTeam!=1" class="goods-price2">个人模式</view>
						<view class="publish-goods-btn1" @click="goJobDetail(item.Id,item.JobName)">详情</view>
					</view>
				</view>
		</view>
	</view>
</template>

<script>
import request from '@/common/request.js';
import unifab from "@/components/beyondGod-drag/beyoundGod-drag.vue";	
export default {
	components: {
			unifab
		},
	data() {
		return {
			count:{
				overdue:0,
				undering:0,
				all:0
			},
			themeColor: '#0079FE',
			authMessage:'',
			activeColor: '#0081ff',
			getData:{
				type:2,
			},
			dataList:[],
			jobList:[],
			current: 0,
			swiperCurrent: 0,
			tabsHeight: 0,
			dx: 0,
			goodsNav: 2,
			showDaiBan:0,
			showWorkOrder:0
		};
	},
	mounted() {
		console.log('mounted')
	},
	computed: {
	},
	onLoad() {
		let that=this
		that.getTaskList();
		that.GetMyTaskListCount();
	},
	onShow(){
		let that=this
		that.getTaskList();
		that.GetMyTaskListCount();
	},
	methods: {
		goHome(){
			//返回首页
			setTimeout(() => {
				 uni.reLaunch({
					url: '/pages/index/tabbar?PageCur=home'
				 });
			}, 0)
		},
		goJobDetail(Id,JobName){
			uni.navigateTo({
				url: '/pages-weibao/wbJobDetail?id='+Id+'&JobName='+JobName
			})
		},
		setNav(goodsNav) {
			console.log('setNav')
			let that=this
			that.goodsNav=goodsNav
			that.getData.type = goodsNav
			that.getTaskList();
		},
		goOverdueWb(Id,zhouqi){
			uni.navigateTo({
				url: '/pages-weibao/goOverdueWb?jobId='+Id+'&zhouqi='+zhouqi+'&isOverdue='+1
			})
		},
		goWB(Id,zhouqi){
			uni.navigateTo({
				url: '/pages-weibao/goOverdueWb?jobId='+Id+'&zhouqi='+zhouqi+'&isOverdue='+0
			})
		},
		getTaskList(){
			let that=this
			uni.showLoading({
				title: '加载中...'
			})
			let opts = {
				url: 'spareapi/GetMyTaskList',
				method: 'get'
			};
			request.httpTokenRequest(opts,that.getData).then(res => {
				uni.hideLoading();
				if(res.data.code == 1){
					if(that.goodsNav==1||that.goodsNav==2){
						that.dataList=res.data.data
					}
					if(that.goodsNav==3){
						that.jobList=res.data.data
					}
				}
				else{
					uni.showToast({ title: res.data.msg, icon: 'none' });
				}
			});
		},
		GetMyTaskListCount(){
			let that=this
			uni.showLoading({
				title: '加载中...'
			})
			let opts = {
				url: 'spareapi/GetMyTaskListCount',
				method: 'get'
			};
			request.httpTokenRequest(opts,that.getData).then(res => {
				uni.hideLoading();
				if(res.data.code == 1){
					that.count.overdue=res.data.data.overdue
					that.count.undering=res.data.data.undering
					that.count.all=res.data.data.all
				}
				else{
					uni.showToast({ title: res.data.msg, icon: 'none' });
				}
			});
		},
	}
};
</script>

<style lang="scss" scoped>
	.cu-tag.badge{
		top:-10rpx !important;
		right:30rpx !important;
	}
	.goods-item-wrap-now{
		//border:2px solid #00B52A;
	}
	.goods-item-wrap {
		border-radius: 8rpx;
		background: #FFFFFF;
		display: flex;
		padding: 24rpx;
		margin: 12rpx;
		//width:100%;
		.goods-content-wrap{
			width: 100%;
		}
		.goods-name {
			width: 100%;
			font-size: 32rpx;
			font-weight: bold;
			display: flex;
			position: relative;
			border-bottom: 1px solid #F3F4F8;
			padding-bottom: 20rpx;
		}
		.goods-name-title{
			display: block;
			float: left;
		}
		.goods-name-type{
			display: block;
			float:right;
			color: #3B69FD;
			margin-right: 20rpx;
		}
		.goods-stock-wrap {
			display: flex;
			color: #969696;
			font-size: 24rpx;
			margin-top: 20rpx;
			justify-content: space-between;
		}
		
		.goods-stock {
			margin-right: 24rpx;
			font-size: 28rpx;
			color: #636571;
			line-height: 32rpx;
		}
		.goods-stock-isok{
			margin-right: 10rpx;
			font-size: 38rpx;
			color: #00B52A;
			line-height: 32rpx;
			font-weight: 700;
		}
		.goods-stock-middle{
			margin-right: 10rpx;
			font-size: 38rpx;
			color: #636571;
			line-height: 32rpx;
			font-weight: 700;
		}
		.goods-stock-notok{
			margin-right: 24rpx;
			font-size: 38rpx;
			color: #F53F3E;
			line-height: 32rpx;
			font-weight: 700;
		}
		.goods-stock-time {
			margin-right: 24rpx;
			font-size: 28rpx;
			color: #e7612e;
			padding-bottom: 20rpx;
		}
		.goods-shangxiaxian {
			font-size:24rpx;
			color: #3F71C4;
			margin-top: 14rpx;
		}
		
		.goods-price1 {
			font-size:26rpx;
			color: #3B69FD;
			margin-top: 20rpx;
			font-weight:500;
			width: 160rpx;
			display: block;
			float:left;
			background-color: #D0D9F7;
			border-radius: 4rpx;
			text-align: center;
			height: 54rpx;
			line-height: 54rpx;
		}
		.goods-price2 {
			font-size:26rpx;
			color: #15C9CA;
			margin-top: 20rpx;
			font-weight:500;
			width: 160rpx;
			display: block;
			float:left;
			background-color: #C8ECEC;
			border-radius: 4rpx;
			text-align: center;
			height: 54rpx;
			line-height: 54rpx;
		}
		.goods-option-item {
			padding: 8rpx 16rpx;
			border-radius: 36rpx;
			font-size: 24rpx;
			margin-top: 24rpx;
		}
	}
	
.wrap {
	display: flex;
	flex-direction: column;
	height: calc(100vh - var(--window-top));
	width: 100%;
}
.swiper-box {
	flex: 1;
}
.swiper-item {
	height: 100%;
}

	.goods-option-item {
		padding: 8rpx 16rpx;
		border-radius: 36rpx;
		font-size: 24rpx;
		margin-top: 24rpx;
	}

	.goods-option-item:not(:last-child) {
		margin-right: 24rpx;
	}

	.goods-option-item-action {
		background: #f1f0fe;
		color: #6991ce;
	}

	.goods-item-wrap {
		margin-top: 24rpx;
	}

	.goods-header-wrap {
		display: flex;
		align-items: center;
		padding: 24rpx;
		background: #FFFFFF;
		margin-bottom: 10rpx;
	}
	.goods-header-item{
		width:49%;
		text-align: center;
	}
	.goods-header-item-active{
		font-size: 30rpx;
		font-color: #333333;
		font-weight: bold;
		position: relative;
	}
	.goods-header-item-active::after{
		position: absolute;
		left: 50%;
		right: 0;
		background: #4372fe;
		height: 8rpx;
		content: "";
		bottom: -12rpx;
		width: 60rpx;
		margin-left: -30rpx;
		border-radius: 200rpx;
	}
	.goods-header-item-action {
		// font-size: 32rpx;
		// font-color: #333333;
		// font-weight: bold;
		position: relative;
	}

	.goods-header-item-action::after {
		// position: absolute;
		// left: 0;
		// right: 0;
		// background: #4372fe;
		// height: 8rpx;
		// content: "";
		// bottom: -12rpx;
	}
	.extraPosition{
		position: absolute;
		right: -5rpx;
		top: -10rpx;
		font-size: 20rpx;
		padding: 0rpx 10rpx;
		height: 28rpx;
		color: #ffffff;
		background-color: #dd514c;
		display: inline-flex;
		align-items: center;
		justify-content: center;
	}
	
	.publish-goods-btn {
		width:160rpx;
		background: #e7612e;
		color: #FFFFFF;
		height: 54rpx;
		line-height: 54rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 82rpx;
		float:right;
		margin-right: 20rpx;
		margin-top: 20rpx;
	}
	
	.publish-goods-btn1 {
		width:160rpx;
		background: #3B69FD;;
		color: #FFFFFF;
		height: 54rpx;
		line-height: 54rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 82rpx;
		float:right;
		margin-right: 20rpx;
		margin-top: 20rpx;
	}
	
	.publish-goods-btn2 {
		width:160rpx;
		background: #00B52A;;
		color: #FFFFFF;
		height: 54rpx;
		line-height: 54rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 82rpx;
		float:right;
		margin-right: 20rpx;
		margin-top: 20rpx;
	}
	
	
	.select-icon{
		border-bottom: 3rpx solid #999;
		border-right: 3rpx solid #999;
		width: 16rpx;
		height: 16rpx;
		transform: rotate(-45deg);
		position: absolute;
		right: 20rpx;
		top: 14rpx;
	}
</style>

